<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>模拟一个数据监测</title>
</head>
<body>
    <script>
        let data = { name: '张三', age: 18 }
        function Observer(obj) {
            const keys = Object.keys(obj)
            keys.forEach(key => {
                Object.defineProperty(this, key, {
                    get() {
                        return obj[key]
                    },
                    set(value) {
                        console.log(`${key}被修改了，我要去解析模板，生成新的虚拟 DOM......`)
                        obj[key] = value
                    }
                })
            })
        }
        const _data = new Observer(data)
        console.log('_data:', _data)
    </script>
</body>
</html>